73A - The Elder Trolls IV Oblivon - CodeForces Solution


greedy math *1600

Please click on ads to support us..

Python Code:

a = b = c = 1
x, y, z, k = [int(s) for s in input().split()]

while (a < x or b < y or c < z) and k > 0:
    if k > 0 and a < x:
        a += 1
        k -= 1
    if k > 0 and b < y:
        b += 1
        k -= 1
    if k > 0 and c < z:
        c += 1
        k -= 1

print(a * b * c)

C++ Code:

#include <bits/stdc++.h>
using namespace std;
int mini,maxi,sred;
long long wynik(int a,int b,int c){
    a = min(mini,a);
    b = min(sred,b);
    c = min(maxi,c);
    //cout << a << " " << b << " " << c << '\n';
    return (long long)(a+1)*(b+1)*(c+1);
}
int main(){
    int x,y,z,k;
    cin >> x >> y >> z >> k;
    x--;
    y--;
    z--;
    mini = min(x,min(y,z));
    maxi = max(x,max(y,z));
    sred = x + y + z - mini - maxi;
    int a,b,c;
    if(mini * 3 >= k){
       a = k/3;
       k -= a;
       b = k/2;
       c = k - b;
       cout << wynik(a,b,c);
    }
    else{
        a = mini;
        k -= a;
        if(k <= 2 * sred){
            cout << wynik(a,k/2,k - k/2);
        }
        else{
            cout << wynik(a,sred,k - sred);
        }
    }
}


Comments

Submit
0 Comments
More Questions

313B - Ilya and Queries
579A - Raising Bacteria
723A - The New Year Meeting Friends
302A - Eugeny and Array
1638B - Odd Swap Sort
1370C - Number Game
1206B - Make Product Equal One
131A - cAPS lOCK
1635A - Min Or Sum
474A - Keyboard
1343A - Candies
1343C - Alternating Subsequence
1325A - EhAb AnD gCd
746A - Compote
318A - Even Odds
550B - Preparing Olympiad
939B - Hamster Farm
732A - Buy a Shovel
1220C - Substring Game in the Lesson
452A - Eevee
1647B - Madoka and the Elegant Gift
1408A - Circle Coloring
766B - Mahmoud and a Triangle
1618C - Paint the Array
469A - I Wanna Be the Guy
1294A - Collecting Coins
1227A - Math Problem
349A - Cinema Line
47A - Triangular numbers
1516B - AGAGA XOOORRR